import React, { Component } from 'react'

import { HashRouter, BrowserRouter, Route } from 'react-router-dom';
import localRoutes from './route';

class Router extends Component<any> {

    renderRoute() {
        return localRoutes.map((item) => {
            if (item.auth) {
                return <Route
                    exact={item.path === '/' ? true : false}
                    key={item.path}
                    path={item.path}
                    component={() => <item.component />}
                />
            }
        })
    }

    render() {
        let { mode } = this.props;
        return (
            <React.Fragment>

                {
                    mode == "hash" ? <HashRouter >
                        {
                            this.renderRoute()
                        }
                    </HashRouter> :
                        <BrowserRouter>
                            {
                                this.renderRoute()
                            }
                        </BrowserRouter >
                }

            </React.Fragment>
        )
    }
}


export default Router
